package org.example.consultant.tools;

import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.example.consultant.pojo.Reservation;
import org.example.consultant.service.ReservationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class ReservationTool {

    @Autowired
    private ReservationService reservationService;

    //1.工具方法：添加预约信息
    @Tool("预约报名服务")
    public void addReservation(
            @P("姓名")String name,
            @P("性别")String gender,
            @P("手机号") String phone,
            @P("沟通时间，格式为: yyyy-MM-dd'T'HH:mm")String communicationTime,
            @P("省份")String province,
            @P("价格")Integer estimatedScore
    ){
        Reservation reservation = new Reservation(null, name, gender, phone, LocalDateTime.parse(communicationTime), province, estimatedScore);
        reservationService.insert(reservation);
    }

    //2.工具方法: 查询预约信息
    @Tool("根据手机号查询预约单")
    public Reservation findReservation( @P("手机号") String phone){
        return reservationService.findByPhone(phone);
    }
}
